window.Dute = function($params){
	var $dutement = new $Dutement($params);
	return $params;
}
window.Page = function($params){
	window.pageParams = $params;
}
window.Dute.components={};
window.Component = window.Dute.Component = window.Dute.$Component = function($params){
	$params.type = window.Dute.componentName;
	return window.Dute.components[$params.type] = $params;
} 
window.Dute.registComponent = function($tagName,$html,$style,$script,$json){
	var $component = window.Dute.components[$tagName] = {};
	if($script){
		$component = eval($script);
	}
	if($style){
		var $styleNode = document.createElement("style");
		$styleNode.innerHTML = $style;
		document.head.appendChild($styleNode);
	}
	$component.template = $html;
	$component.jsonString = $json;
	window.Dute.components[$tagName] = $component;
}
window.isIE = (!(window.addEventListener));
window.includes = {};
var $include = window.Dute.components.include = {};
{
	$include.type = "include";
	$include.title = "引用";
	$include.onData = function($data,$dutement){
		if(!$dutement.included){
			var $THIS = this;
			var $request = null;
			try{	
				 $request = new window.XMLHttpRequest();
			}catch(e){
				 try{
					 $request=ActiveXobject("Msxml12.XMLHTTP");
				 }catch(e1){
					 try{
						 $request=ActiveXobject("Microsoft.XMLHTTP");
					 }catch(e2){ 
						 console.log(e2);
					 }
				 }
			 }
			var $url = $dutement.params.src;
			if(window.includes[$url]){
				$dutement.doc.innerHTML = $dutement.params.template = window.includes[$url];
			}else{
				$request.open("GET",$url, false);
				$request.onreadystatechange = function() {
			        if($request.readyState == 4 && $request.status == 200) {
			        	window.includes[$url] = $dutement.doc.innerHTML = $dutement.params.template = $request.responseText.replace(/src\=([\"'])\{\{/g, "s_r_c="+'$'+'1'+"{{");
			        }else{
			        	$dutement.doc.innerHTML = "";
			        }
			    };
			    $dutement.included = true;
		    	$request.send();
			}
		}
	}
} 

window.$Dutement=window["$"+"Dutement"]=window.Dutement=function($params){
	if(typeof($params)=="string"){
		$params={target:document.getElementById($params)};		
	}
	this.index = Dute.count++; 
	this.params = $params;
	this.target = $params.target || document.createElement("template");
	this.docPoint = document.createTextNode("");
	var $template = null;
	if(this.target.className){
		this.target.className = (this.target.className||"").replace("dute-view","").trim();
	}
	
	if($params.name || $params.id){
		window[$params.name || $params.id] = $params;
	}
	
	if($params.type=="include"||$params.type=="import"){
		$template=$params.template;
		if(this.target.nodeType==1){
			this.target.innerHTML = "";
		}
		this.docPoint = this.target;
	}else if(typeof($params.template)!="undefined"){
		$template=$params.template;
		if(this.target){
			this.target.appendChild(this.docPoint);
		}
	}else if(this.target.tagName.toLowerCase()=="template"){
		$template=this.target.innerHTML;		
		this.target.innerHTML = "";
		this.target.parentNode.insertBefore(this.docPoint,this.target);
		$params.target.remove();		
	}else if(this.target.tagName.toLowerCase()=="body"||this.target.tagName.toLowerCase()=="html"){
		$template=this.target.innerHTML;
		this.target.innerHTML = "";		
		this.target.appendChild(this.docPoint);
		this.target.style.display="";
		window.bodyPage = $params;
	}else{
		$template=this.target.outerHTML;
		this.target.innerHTML = "";
		this.target.parentNode.insertBefore(this.docPoint,this.target);
		$params.target.remove();
	}	
	try{
		this.target.dute = this;
	}catch(ex){	
	}
	this.doc = document.createElement("doc");	
	this.template = $template;
	if(this.template){
		this.doc.innerHTML = this.template.replace(/src\=([\"'])\{\{/g, "s_r_c="+'$'+'1'+"{{");
	}
	if(this.target.tagName && this.target.tagName.toLowerCase()=="body"){
		this.target.duteNode = this.doc;
		this.target.dute = this;
	}
	this.mapping=[];
	this.nodeing={};
	this.htmling=[];
	this.serialVersionUID = 0;
	var THIS = this;
	$params.setData = function(data,$bReload){		
		return THIS.setData(data,$bReload);
	};
	$params.getData = function(){		
		return this.data;
	};
	if(!$params.onLoad){
		$params.onLoad = function(options){}
	}
	if(!$params.onReady){
		$params.onReady = function(){}
	}
	if(!$params.onRender){
		$params.onRender = function(){}
	}
	$params.getOutput = function(){
		return THIS.$output; 
	}
	$params.clear = function(){
		THIS.clear();
	}
	
	var $options = {}; 
	{
		var $url = window.location.search;
		if ($url.indexOf("?") != -1) { 
			var $str = $url.substr(1); 
			$strs = $str.split("&"); 
			for(var $i = 0; $i < $strs.length; $i ++) {
				var $key = $strs[$i].split("=")[0];
				$key = $key.replace("%24","$");
				var $val = $strs[$i].split("=")[1];
				if(typeof($val)!="undefined"){
					$options[$key]=window[$key]=decodeURIComponent($val);
				}
			} 
		}
		window.basePath = window.location.href.substring(0,window.location.href.indexOf("/",8)+1);
	}
	window._options = $options;
	$params.onLoad($options);
	if(!$params.parent){
		$params.setData($params.data);
	}
	return $params;
};

window.Page = function($params,$target){
	if(window.getTargetPage){
		$params.target = window.getTargetPage();
		window.getTargetPage = null;
		return new window.$Dutement($params);
	}else{
		if($target){
			$params.target = $target;
		}
		window.lazyPageParams = $params;		
	}
}
window.getPage = function(){
	return window.bodyPage || window.lazyPageParams;
}
$Dutement.debug = true;

$Dutement.prototype.getData = function(){
	return this.params.data;
}
$Dutement.prototype.getHtml = function(){
	return this.getCode(this.doc,this.index||1).html;
}
$Dutement.prototype.getCode = function($parentNode,$index){
	var $html = "";
	var $nodes = $parentNode.childNodes;
	var $i = 0;
	var $preNode = null;
	var $lastType = 0;
	var $have = false;
	for(var i=0;i<$nodes.length;i++){
		var $node = $nodes[i];
		if($node.nodeType==3 && $node.data.trim()=="")continue;
		if($node.nodeType==1){
			var $tag = $node.tagName.toLowerCase();
			if($tag=="br"){
				$html+="<br/>";
			}else{
				$html+=this.getBlank($index)+"<"+$tag;
				var $attributes = $node.attributes;
				for(var j=0;j<$attributes.length;j++){
					$html+=' '+($attributes[j].name=='s_r_c'?'src':$attributes[j].name);
					$html+='=\"'+$attributes[j].value+'\"';
				}
				$html+=">";
				if($tag=="pre"||$tag=="code"){
					$html+=$node.innerHTML;
					$html+="</"+$tag+'>\r\n';
				}else{
					var $code = this.getCode($node,$index+1);
					$html+=($code.have==""?"":'\r\n')+$code.html;
					$html+=(($code.have=="" || $code.lastType==3)?"":this.getBlank($index))+"</"+$tag+'>\r\n';
				}
			}
			$have=true;
			$lastType=1;
		}else if($node.nodeType==3){
			$html+=$node.data.trim();
			$lastType=3;
		}
	}
	return {html:$html,have:$have,lastType:$lastType};
}
$Dutement.prototype.getBlank = function($index){
	var $blank="";
	for(var i=0;i<$index;i++){
		$blank+='\t';
	}
	return $blank;
}



$Dutement.prototype.getNodes = function($parentNode,$list,$index,$noEmpty){
	var $nodes = $parentNode.childNodes;
	var $i = 0;
	var $preNode = null;
	for(var i=0;i<$nodes.length;i++){
		var $node = $nodes[i];
		if($node.nodeType==3 && $node.data.trim()=="" && !$noEmpty)continue;
		var $nodeInfo = {node:$node,nodeType:$node.nodeType,parentNode:$parentNode,preNode:$preNode};
		$nodeInfo.idx = $index+","+$i++;
		$list.push($nodeInfo);
		if($node.nodeType==1){
			var $tag = $node.tagName.toLowerCase();
			if(!($tag=="pre"||$tag=="code")){
				this.getNodes($node,$list,$nodeInfo.idx);
			}
		}
		if($node.getAttribute && $node.getAttribute($Dutement.config.tagPrefix+"if") && $Dutement.config.engine){
			$list.push({nodeType:11,idx:$nodeInfo.idx});
		}
		if($node.getAttribute && $node.getAttribute($Dutement.config.tagPrefix+"for") && $Dutement.config.engine){
			$list.push({nodeType:12,idx:$nodeInfo.idx});
		}
		$preNode = $node;
		
	}
	return $list;
}

var $scripts = document.getElementsByTagName("script");
for(var i=0;i<$scripts.length;i++){	
	if($scripts[i].getAttribute("src") && $scripts[i].getAttribute("src").indexOf("dute-1.0.js")>-1 && $scripts[i].getAttribute("prefix")){
		window.duteTag = $scripts[i].getAttribute("prefix");
	}
}

$Dutement.config={};
$Dutement.config.engine=true;
$Dutement.config.tag=window.duteTag||"wx";
$Dutement.config.tagPrefix=$Dutement.config.tag+":";
window[$Dutement.config.tag]={
	idin:function($arr,$itm){
		var $arrs = $arr.split(",");
		for(var $o in $arrs){
			if($arrs[$o].replace(/[#]/g,"").trim()==$itm.replace(/[#]/g,""))return true;
		}
		return false;
	},
	bitin:function($num,$itm){
		return ($num & $itm) == $itm;
	},
	htm:function($content){
		return $content;
	},
	html:function($content){
		return $content;
	},
	set:function($name,$value){
		window[$name]=$value;
		return "";
	},
	split:function($string,$separator){
		return $string.split($separator);
	},
	queryString:function($a,$b,$c,$d,$e){
		var $queryString = ""; 
		{
			var $url = window.location.search;
			if ($url.indexOf("?") != -1) { 
				var $str = $url.substr(1); 
				$strs = $str.split("&"); 
				for(var $i = 0; $i < $strs.length; $i ++) {
					var $key = $strs[$i].split("=")[0];
					var $val = $strs[$i].split("=")[1];
					if($val && $key!=$a && $key!=$b && $key!=$c && $key!=$d && $key!=$e){
						if($queryString)$queryString+="&";
						$queryString+=$key+"="+$val;
					}
				} 
			}
		}
		return $queryString;
	},
	eval:function($str){
		if(!$str)return null;
		return eval("("+$str+")");
	},
	get:function(type,flag){
		if(window.getFlag){
			return window.getFlag(type,flag);
		}
	}
}

$Dutement.match=function($content,$regex,$matchCallback,$unMatchCallback){
	if(!$content)return "";
	var $expr = null;
	var $replaceStr = "";
	var $lastIndex = 0;
	if(!$unMatchCallback){
		$unMatchCallback = function($content){
			return $content;
		}
	}
	var $index = 0;
	while($expr=$regex.exec($content)){
		var $unMatched = $content.substring($lastIndex,$expr.index);
		if($unMatched){
			$replaceStr += $unMatchCallback($unMatched);
		}
		var $matched = $expr[$expr.length-1];
		if(!$matched && $expr.length==3){
			$matched = $expr[$expr.length-2];
		}
		if($matched){
			$replaceStr += $matchCallback($matched);
		}
		$lastIndex = $regex.lastIndex;
	}
	var $endMatched = $content.substring($lastIndex);
	if($endMatched){
		$replaceStr += $unMatchCallback($endMatched);
	}
	return $replaceStr;
}


$Dutement.join=function(arr,separator){
	return "-"+arr.join(",");
}
$Dutement.array=function($count,$first){
	var $arr = [];
	for(var $i=$first;$i<$count+1;$i++){
		$arr.push($i);
	}
	return $arr;
}


$Dutement.regexps = {};
$Dutement.newRegExp=function($strRegExp,$g){
	var $regExp = $Dutement.regexps[$strRegExp];
	if($regExp)return $regExp;
	return $Dutement.regexps[$strRegExp] = new window.RegExp($strRegExp,$g);
}

$Dutement.prototype.compile = function($data){
	var $start = new Date();
	$Dutement.eval=function($content,$params){
		if(!$Dutement.config.engine){
			return $content;
		}
		$content = $content.replace($Dutement.newRegExp("^\{\{"),"").replace($Dutement.newRegExp("\}\}$"),"");
		if($content.indexOf("[")==0||$content.indexOf("{")==0||$content.indexOf(").")>-1){
			try{
				return eval("("+$content+")"); 
			}catch(ex){
				console.log($content);
				console.error(ex);
			}
		}
		$content = $Dutement.match($content,$Dutement.newRegExp("(['][^']+['])|([\"][^\"]+[\"])","g"),function($content){		
			return $content;
		},function($content){
			return $content.replace($Dutement.newRegExp("[\.]([a-zA-Z0-9_\$]+)","g"),"[\"$"+"1\"]");
		});
		$content = $Dutement.match($content,$Dutement.newRegExp("(['][^']+['])|([\"][^\"]+[\"])","g"),function($content,$index){
			return $content;
		},function($content){
			return $content.replace($Dutement.newRegExp("([a-zA-Z0-9_\$]+)","g"),"[\"$"+"1\"]");
		});
		$content = $Dutement.match($content,$Dutement.newRegExp("(['][^']+['])|([\"][^\"]+[\"])","g"),function($content,$index){
			return $content;
		},function($content){
			return $content.replace(/\]\[/g,",");
		});
		$content = $Dutement.match($content,$Dutement.newRegExp("(['][^']+['])|([\"][^\"]+[\"])","g"),function($content,$index){
			return $content;
		},function($content){
			return $content.replace(/\]/g,")").replace(/\[/g,"$Dutement.lookup(");
		});
		
		try{
			var $val = eval("("+$content+")");
			return $val;
		}catch(ex){
			console.log($content);
			console.error(ex);
		}
	}
	$Dutement.el=function($content,$params){
		var $value = $Dutement.eval($content,$params);
		if($value && $value.nodeType){
			return "";
		}
		if(typeof($value)!="string"){
			return JSON.stringify($value);
		}else{
			return $value;
		}
	}
	$Dutement.lookup=function(){
		var $vars = arguments;
		var $var = eval("typeof("+$vars[0]+")=='undefined'?null:"+$vars[0]+"");		
		if(typeof($var)=="undefined" || $var==null)return "";
		for(var $i=1;$i<$vars.length;$i++){
			var $vName = $vars[$i];
			if(typeof($var[$vName])=="undefined"){
				return "";
			}
			$var = $var[$vName];
		}
		return typeof($var)=="undefined"?"":$var;
	}
	
	$Dutement.parse=function($node,$iddx){
		var $result = {
			type:$node.nodeType,
			iddx:$iddx,
			duteNode:$node
		};
		if($node.nodeType==1){
			$result.tag = $node.tagName.toLowerCase()
			if($Dutement.config.engine){
				$result.tag = $result.tag.replace($Dutement.config.tagPrefix,"");
			}
			var $attributes = $node.attributes;	
			var $datas = {};
			var $attrs = {};
			for(var i=0;i<$attributes.length;i++){
				if($attributes[i].value && $attributes[i].value.indexOf("{{")>-1){
					$datas[$attributes[i].name] = "";
					$datas[$attributes[i].name] = $Dutement.match($attributes[i].value,$Dutement.newRegExp("\{\{[^\n]+?\}\}","g"),function($content){
						return $Dutement.el($content);
					});
				}else{
					$datas[$attributes[i].name] = $attributes[i].value;
				}
				$attrs[$attributes[i].name] = $attributes[i].value;
			}
			if($result.tag=="textarea"){
				if($node.value.indexOf("{{")>-1){
					$datas["value"] = $Dutement.match($node.value,$Dutement.newRegExp("\{\{[^\n]+?\}\}","g"),function($content){
						return $Dutement.el($content);
					});
				}else{
					$datas["value"] = $node.value;
				}
				$attrs["value"] = $node.value;
			}
			$result.datas = $datas;	
			$result.attrs = $attrs;
			$node.nodes=[];
			if($result.tag=="pre"||$result.tag=="code"){
				$result.content = $node.innerHTML;
			}
		}else if($node.nodeType==3){
			$result.data = $node.data;			
			if($node.data.indexOf("{{")>-1){				
				$result.content = $Dutement.match($node.data,$Dutement.newRegExp("\{\{[^\n]+?\}\}","g"),function($content){
					return $Dutement.el($content);
				});
			}else{
				$result.content = $node.data;
			}
		}
		return $result;
	}
	if(this.params.jsonString){
		var $reg = $Dutement.newRegExp("\{\{[^\n]+?\}\}","g");
		var $strJson = "{}";
		var $js = "{\n";
		for(var o in $data){
			if(o.indexOf(".")==-1){
				$js += "var "+o+" = $data[\""+o+"\"];\n";
			}
		}
		$js+="$strJson = $Dutement.match(this.params.jsonString,$reg,function($content){return $Dutement.el($content);});\n";
		$js+="}\n";
		eval($js);
		this.json = this.params.json = eval("("+$strJson+")");
	}	
	{
		var $list = [];
		
		var $nodes = this.getNodes(this.doc,$list,this.index||1);	

		var $js = "{var name=null;var id=null;\n";
		var $params = this.params;		
		for(var o in $params){
			if(o.indexOf(":")==-1){
				$js += "var "+o+" = $params[\""+o+"\"];\n";
			}
		}
		for(var o in $data){
			if(o.indexOf(".")==-1){
				$js += "var "+o+" = $data[\""+o+"\"];\n";
			}
		}
		var $for = 0;
		var _F_ = [];
		for(var $i=0;$i<$nodes.length;$i++){
			var $nodeInfo = $nodes[$i];
			var $node = $nodeInfo.node;
			var $b = "";
			for(var o in $nodeInfo.idx.split(",")){
				$b+="	";
			}
			if($nodeInfo.nodeType>10){
				$js+=$b+"}\n";
				if($nodeInfo.nodeType==12){
					$js+=$b+"_F_.pop();\n";
				}
				continue;
			}
			if($nodeInfo.nodeType!=1 && $nodeInfo.nodeType!=3)continue;
			if($nodeInfo.nodeType==1){
				if($node.getAttribute($Dutement.config.tagPrefix+"for") && $Dutement.config.engine){
					$for++;
					$js+=$b+"_F_.push(0);\n";
					$js+=$b+"var for_list_"+$for+" = Dutement.eval($nodes["+$i+"].node.getAttribute(Dutement.config.tagPrefix+\"for\"));\n";
					var $keyName = ($node.getAttribute($Dutement.config.tagPrefix+"for-key")||"key");
					var $itemName = ($node.getAttribute($Dutement.config.tagPrefix+"for-item")||"item");
					var $indexName = ($node.getAttribute($Dutement.config.tagPrefix+"for-index")||"index");
					$js+=$b+"var for_index_"+$for+" = -1;\n";
					$js+=$b+"if(typeof(for_list_"+$for+")=='number'){for_list_"+$for+"=Dutement.array(for_list_"+$for+",Dutement.eval($nodes["+$i+"].node.getAttribute(Dutement.config.tagPrefix+\"for-first\")));}\n";
					$js+=$b+"if(for_list_"+$for+")\n";
					$js+=$b+"for(var for_key_"+$for+" in for_list_"+$for+"){\n";
					$js+=$b+"for_index_"+$for+"++;\n";
					$js+=$b+"_F_[_F_.length-1] = for_index_"+$for+";\n";
					$js+=$b+"var for_item_"+$for+" = for_list_"+$for+"[for_key_"+$for+"];\n";
					
					$js+=$b+"var "+$keyName+"=for_key_"+$for+";\n";
					$js+=$b+"var "+$itemName+"=for_item_"+$for+";\n";
					$js+=$b+"var "+$indexName+"=for_index_"+$for+";\n";
				}
				if($node.getAttribute($Dutement.config.tagPrefix+"if") && $Dutement.config.engine){
					$js+=$b+"if(Dutement.eval($nodes["+$i+"].node.getAttribute(Dutement.config.tagPrefix+\"if\"))){\n";
				}
				$js+=$b+"this.mapping[this.mapping.length]=Dutement.parse($nodes["+$i+"].node,$nodes["+$i+"].idx+Dutement.join(_F_));\n";
			}
			if($node.nodeType==3){
				$js+=$b+"this.mapping[this.mapping.length]=Dutement.parse($nodes["+$i+"].node,$nodes["+$i+"].idx+Dutement.join(_F_));\n";
			}
		}
		$js+="}\n";
		
		try{
			eval($js);
		}catch(ex){
			console.log($js);
			console.log(ex);
		}		
	}
	
	delete $Dutement.eval;
	delete $Dutement.lookup;
	delete $Dutement.parse;
	$Dutement.eval = null;
	$Dutement.lookup = null;
	$Dutement.parse = null;
}


$Dutement.prototype.clear = function(){	
	var $ids = [];
	for(var $o in this.nodeing){
		$ids.push($o);
	}
	for(var $o in $ids){
		var $node = this.nodeing[$ids[$o]].node;
		if(!window.isIE){
			$node.remove();
		}else{
			$node.parentNode.removeChild($node);
		}
		if(this.nodeing[$ids[$o]].dutement){
			this.nodeing[$ids[$o]].dutement.clear();
		}
		delete this.nodeing[$ids[$o]];
	}
}


$Dutement.prototype.setData=function($data,$bReload,$bDebug){
	
	
	if(this.params.onData){
		this.params.onData($data,this);
	}
	
	if(!this.params.data){
		this.params.data={};
	}
	for(var $o in $data){
		this.params.data[$o]=$data[$o];
	}
	
	if($bReload){
		this.clear();
	}

	var $start = new Date();
	this.serialVersionUID ++;
	this.mapping = [];	
	this.compile(this.params.data);
	
	
	this.nodes = [];
	var $elements = {};
	var $path = [];
	
	for(var o in this.htmling){
		var $node = this.htmling[o];
		if($node && $node.parentNode){
			$node.parentNode.removeChild($node);
		}
	}
	this.htmling = [];
	
	
	var $components = [];
	
	
	
	for(var o in this.mapping){
		var $info = this.mapping[o];
		var $iddx = $info.iddx;
		var $node = $elements[$info.iddx];
		if(!$node){		
			$node = this.nodeing[$info.iddx];
			if(!$node){				
				if($info.type==3){
					$node = {node:document.createTextNode("")};
				}else if($info.type==1){
					if($info.tag=="block"||$info.tag=="include"||$info.tag=="import"){
						$node = {node:document.createTextNode("")};
						$node.isBlock = true;
					}else{
						if(window.isIE && $info.datas.type){
							$node = {node:document.createElement("<"+$info.tag+' '+"type='"+$info.datas.type+"'></"+$info.tag+">")};
						}else{
							$node = {node:document.createElement($info.tag)};
						}
						$node.node.duteNode = $info.duteNode;
						$node.node.dute = this.params;
						$node.node.iddx = $info.iddx;
					}
				}
				
				$node.iddx = $info.iddx;
			}
				
			
			var $parentNode = null;
			var $siblingNode = null;				
			if($path.length){
				var $lastNode = $path[$path.length-1];
				if($iddx.split("-")[0].split(",").length == $lastNode.iddx.split("-")[0].split(",").length){
					$siblingNode = $lastNode;
					$path[$path.length-1] = $node;
				}else if($iddx.split("-")[0].split(",").length > $lastNode.iddx.split("-")[0].split(",").length){
					$parentNode = $lastNode;
					$path[$path.length] = $node;
				}else{
					var $eq = $path.length-1;
					for(var $i=$path.length-1;$i>-1;$i--){
						$lastNode = $path[$i];
						if($lastNode.iddx.split("-")[0].split(",").length==$iddx.split("-")[0].split(",").length){
							$eq = $i;
							break;
						}
					}
					$path.splice($eq+1);
					$siblingNode = $lastNode;
					$path[$path.length-1] = $node;
				}
			}else{
				$path[$path.length] = $node;
			}
			if($parentNode && $parentNode.node.nodeType==3){
				$siblingNode = $parentNode;
				$parentNode = null;
			}
			
			
			if(window.Dute.components[$info.tag]){
				//$node.node.innerHTML="";
			}
			
			
			if($parentNode){
				var $arr = $iddx.split("-")[0].split(",");
				if($arr[$arr.length-1]=="0"){
					if($parentNode.node.firstChild){
						if($node.node!=$parentNode.node.firstChild){
							$parentNode.node.insertBefore($node.node, $parentNode.node.firstChild);
						}
					}else{
						if($node.node.parentNode!=$parentNode){
							$parentNode.node.appendChild($node.node);
						}
					}
				}else{
					if($node.node.parentNode!=$parentNode){
						$parentNode.node.appendChild($node.node);
					}
				}
			}else if($siblingNode){
				if($siblingNode.node.nextSibling && !$siblingNode.isBlock){
					if($node.node.previousSibling!=$siblingNode.node){
						$siblingNode.node.parentNode.insertBefore($node.node, $siblingNode.node.nextSibling);
					}
				}else{
					if($node.node.parentNode!=$siblingNode.node.parentNode){
						$siblingNode.node.parentNode.appendChild($node.node);
					}
				}
			}else{
				try{
					if(this.docPoint.nextSibling){
						if($node.node!=this.docPoint.nextSibling){
							this.docPoint.parentNode.insertBefore($node.node,this.docPoint.nextSibling);
						}
					}else{
						if(!this.docPoint.parentNode){
							this.target.appendChild(this.docPoint);
						}
						this.docPoint.parentNode.appendChild($node.node);
					}
					
				}catch(ex){
					console.log(ex.message);
				}
			}
			$path[$path.length-1] = $node;
			this.nodeing[$info.iddx] = $node;
		}
				
		if(this.docPoint.parentNode==$node.node.parentNode){
			this.nodes.push($node.node);
		}
		
		$node.svid = this.serialVersionUID;
		$elements[$info.iddx] = $node;
		$node.info = $info;
		if($info.type==3){
			var $content = $info.content.trim();
			if($info.content && $content.indexOf("<")==0 && $content.lastIndexOf(">")==$content.length-1){
				var $div = document.createElement("div"); 				
				$div.innerHTML = $content;
				var $htmlNodes = $div.childNodes;
				for(var j=0;j<$htmlNodes.length;j++){
					var $htmlNode = $htmlNodes[j];
					if($parentNode.node.firstChild){
						$parentNode.node.insertBefore($htmlNode, $parentNode.node.firstChild);
					}else{
						$parentNode.node.appendChild($htmlNode);
					}
					this.htmling.push($htmlNode);
				}
			}else{
				$node.node.data = $info.content;
			}
		}else if($info.type==1){
			if(!$node.isBlock){
				for(var $name in $info.datas){
					if($name=="value"){
						$node.node.value = $info.datas[$name];						
					}else if($info.datas[$name] || $name.indexOf("data-")==0){
						if($name.indexOf($Dutement.config.tag+":")==-1){
							try{
								if($node.node.getAttribute($name)!=$info.datas[$name]){
									var $strAttr = $info.datas[$name];
									if(typeof($strAttr)=="object"){
										$strAttr = JSON.stringify($strAttr);
									}
									$node.node.setAttribute($name=="s_r_c"?"src":$name,$info.datas[$name]);
								}
							}catch(e1){
								if($name!="type"){
									$node.node[$name] = $info.datas[$name];
								}
							}
						}
					}else{
						$node.node.removeAttribute($name);
					}
					if(this.params.parent && $name=="id" && $info.datas[$name]=="pageStyle"){
						$node.node.removeAttribute($name);
					}
				}
				$node.node.duteNode.datas = $info.datas;
				$node.node.duteNode.attrs = $info.attrs;
				$node.node.duteNode.nodes.push($node.node);
				
				if($node.attributes){
					var $attributes = $node.node.attributes;
					for(var i=0;i<$attributes.length;i++){
						var $name = $attributes[i].name;
						if(!$info.datas[$name] && $name!="value" && $name.indexOf("data-")!=0){
							$node.removeAttribute($name);
						}
					}
				}
			}
			if($info.tag=="pre"||$info.tag=="code"){ 
				$node.node.innerText = $info.content;
			}
			
			if(window.Dute.components[$info.tag]){
				$components.push({
					info:$info,node:$node
				});
			}
		}
	}
	for(var o in $components){
		var $info = $components[o].info;
		var $node = $components[o].node;
		if(!$node.dutement){
			var $params = window.Dute.components[$info.tag];					
			var $newParams = {};
			for(var o in $params){
				$newParams[o] = $params[o]; 
			}
			$params = $newParams;
			$params.type = $info.tag;
			$params.target = $node.node;
			
			for(var o in $info.datas){
				$params[o]=$info.datas[o];
			}
			
			$params.duteNode = $info.duteNode;
			$params.content = $node.node.innerHTML;
			$params.parent = this;
			$node.dutement = new $Dutement($params);
		}
		if($info.tag=="include"||$info.tag=="import"){
			$node.dutement.setData(this.params.data,$bReload);
		}else{
			$node.dutement.content = $node.node.innerHTML;
			//$node.node.innerHTML = "";
			$node.dutement.setData({content:$node.node.innerHTML,datas:$info.datas,attrs:$info.attrs,properties:$node.dutement.properties},$bReload);
		}
		$node.node.dutement = $node.dutement;
	}
		
	var $ids = [];
	for(var $o in this.nodeing){
		$ids.push($o);
	}
	for(var $o in $ids){
		var $node = this.nodeing[$ids[$o]];
		if($node.svid!=this.serialVersionUID){
			if(!window.isIE){
				$node.node.remove();
			}else{
				$node.node.parentNode.removeChild($node.node);
			}
			if($bReload){
				delete $node;
				delete this.nodeing[$ids[$o]];
			}
			continue;
		}
		if(this.params.type!="body" && $node.node.tagName && $node.node.tagName.toLowerCase()=="script" && $node.node.getAttribute("type")=="text/javascript"){
			try{
				eval($node.node.innerText);
			}catch(e){
				console.error("Expression parsing error - "+$node.node.innerText);
			}
		}
	}
	
	if(this.params.type!="body" && this.params.target){
		for(var $o in this.nodeing){
			if(this.nodeing[$o].nodeType==1){
				this.params.target.root = this.nodeing[$o];
			}
		}
	}
	
	if(this.serialVersionUID==1){
		this.params.onReady();
	}
	
	this.params.onRender();
	
	this.$output = "";
	for(var o in this.nodes){
		this.$output+=this.nodes[o].outerHTML;
	}
	
	return this.$output;
}
$Dutement.inited = false;
$Dutement.init = function(){
	if($Dutement.inited)return;
	$Dutement.inited = true;
	if(document.removeEventListener){
		document.removeEventListener( "DOMContentLoaded", $Dutement.init );
		window.removeEventListener( "load", $Dutement.init );
	}else{
		document.detachEvent( "onDOMContentLoaded", $Dutement.init );
		window.detachEvent( "onload", $Dutement.init );
		window.detachEvent( "onreadystatechange", $Dutement.init );
	}
	
	
	var $templates = document.getElementsByTagName("template");
	for(var i=0;i<$templates.length;i++){
		if($templates[i].getAttribute("type")=="text/component"){
			window.Dute.parseComponents($templates[i].getAttribute("src"));
		}
	}
	if(window.Dute.onComponent){
		window.Dute.onComponent();
	}
	
	
	var $templates = [];
	var $views = document.getElementsByClassName("dute-view");
	for(var i=0;i<$views.length;i++){
		$templates.push($views[i]);
	}
	for(var i=0;i<$templates.length;i++){
		var $templateNode = $templates[i];
		if($templateNode.className.indexOf("dute-view")>-1){
			var $params = {};
			$params.target = $templateNode;
			var $dutement = new $Dutement($params);
		}
	}
	
	
	if(window.lazyPageParams){
		if(window.lazyPageParams.target && typeof(window.lazyPageParams.target)=="string"){
			window.lazyPageParams.target = document.getElementById(window.lazyPageParams.target);
		}else{	
			window.lazyPageParams.target = document.body;
		}
		window.lazyPageParams.type = "body";
		var $dutement = new $Dutement(window.lazyPageParams);
		window.lazyPageParams = null;
	}
	
	if(window.Dute.onInit){
		window.Dute.onInit();
	}
}
if(window.attachEvent){
	window.attachEvent("onload",$Dutement.init);
	document.attachEvent( "onDOMContentLoaded", $Dutement.init );
	
    document.attachEvent("onreadystatechange",function(){
    	if(document.readyState=="complete"){
    		$Dutement.init();
	    }
	});
}else{
	document.addEventListener( "DOMContentLoaded", $Dutement.init );
	window.addEventListener("load",$Dutement.init); 
}
if(window.isIE){
	String.prototype.trim = function(){
	    return this.replace(/(^\s*)|(\s*$)/g, "");    
	}
}
function getElementsByClassName(node, className) {
    if (node.getElementsByClassName) {
        
        return node.getElementsByClassName(className);
    } else {
       
        var results = [],
            elems = node.getElementsByTagName("*");
        for (var i = 0, len = elems.length; i < len; i++) {
            if (elems[i].className.indexOf(className) != -1) {
                results[results.length] = elems[i];
            }
        }
        return results;
    }
}


window.Dute.parseComponents = function($path){
	$path+=($path.indexOf("?")>-1?"&":"?")+'mm='+Math.random();
	var $request = new window.XMLHttpRequest(); 
    $request.open("GET", $path, false);
    $request.onreadystatechange = function() {
        if($request.readyState == 4 && $request.status == 200 || $request.status == 0 || $request.status == 304) {
           	var $div = document.createElement("div");
			$div.innerHTML = $request.responseText;
			var $compoNodes = $div.childNodes;
			for(var j=0;j<$compoNodes.length;j++){
				var $componentNode = $compoNodes[j];
				if(!$componentNode || !$componentNode.getAttribute)continue;
				var $compoName = $componentNode.getAttribute("name");
				if($componentNode.tagName.toLowerCase()!="component"||!$compoName)continue;
				var $nodes = $componentNode.childNodes;
				var $html,$style,$script,$json;
				for(var i=0;i<$nodes.length;i++){
					var $node = $nodes[i];
					if($node.nodeType!=1)continue;
					if($node.tagName.toLowerCase()=="template"){
						if($node.getAttribute("type")=="text/html"){
							$html = $node.innerHTML;
						}else if($node.getAttribute("type")=="text/json"){
							$json = $node.innerHTML;
						}
					}else if($node.tagName.toLowerCase()=="script"){
						$script = $node.innerHTML;
					}else if($node.tagName.toLowerCase()=="style"){
						if($node.innerHTML.trim()!=""){
							$style = $node.innerHTML;
						}
					}else{
						console.log("不可识别的组件节点类型 - "+$node.tagName);
					}
				}
				window.Dute.registComponent($compoName,$html,$style,$script,$json);
			}
        }
    };
    $request.send(); 
}